<?php
namespace app\clubadmin\controller;
use \think\Controller;
use \think\captcha\Captcha;
use \think\Db;
use \think\Session;
use app\clubadmin\model\Login;

class Index extends Controller
{
      public function index(){
      if(request()->isPost()){
            $ca=input('verifycode');
            /*echo $ca;*/
            if(!captcha_check($ca)){
                //验证失败
                echo"<script>alert('验证码错误');</script>";
            }else{
                  //判断用户名密码
                  $a=input('adminname');
                  $p=input('password');
                  /*echo $a;
                  echo "1";
                  exit;*/
                  $log=new Login;
                  $result=$log->login($a,$p);
                  if ($result==1) {
                        echo"<script>alert('用户不存在');</script>";
                  }else if($result==2){
                        echo"<script>alert('密码错误');</script>";

                  }else if($result==3){
                    $this->redirect("club_course/index");
                  }
                  //错误分情况提醒，用户不存在、密码错误
            }

      }
        return $this->fetch();
      }
    public function show_captcha(){
        ob_clean();
        $captcha = new Captcha();
        $captcha->fontSize = 32;
        $captcha->length   = 3;
        $captcha->useNoise = false;
        return $captcha->entry();
    }
    public function logout(){
      Session::clear();
      $this->redirect('index/index');
    }

    public function check(){
    $u=input('user');
    $count=Db::name("clubadmins")->where("ca_name",$u)->count();
    echo $count;
    }
    

   /* public function find(){
    	Db::table('clubcourses')
    ->where('name|title','like','thinkphp%')
    ->where('cc_id&cc_name','>',0)
    ->find();

    SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' OR `title` LIKE 'thinkphp%' ) AND ( `cc_id` > 0 AND `cc_name` > 0 ) LIMIT 1
    }*/

}
